﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Test.Properties;
using System.Reflection;

namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            toolTip1.SetToolTip(this.myButton1,"mybutton");
            toolTip1.SetToolTip(this.button1,"buttin");
            Console.WriteLine(myTextBox3.Text);
        }

        Image img = (Image)Resources.red;

        private void myButton1_Click(object sender, EventArgs e)
        {
            myTextBox3.Text += "i";
            myDataGridView.Rows.Add("第一个字段值", "第二个字段值", "第三个字段值");
            myComboBox2.Add("123123123213");
            myComboBox2.Items.Add("456456");
            myTextBox2.Text = (string)myComboBox2.SelectedItem;
            myTextBox1.Text = myDateTimePicker1.Text;
        }

        private void userButton1_Click(object sender, EventArgs e)
        {
            myTextBox2.Text = "myTextBox2";
            myComboBox2.Text = "myComboBox2";
            myDateTimePicker1.Text = "myDateTimePicker1";
        }

        private void dateTimePicker1_DropDown(object sender, EventArgs e)
        {
            Console.WriteLine("Drop down");
        }

        

       // 获取事件
        public static Delegate[] GetObjectEventList(object p_Object, string p_EventName, Type p_EventType)
        {
            PropertyInfo _PropertyInfo = p_Object.GetType().GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
            if (_PropertyInfo != null)
            {
                object _EventList = _PropertyInfo.GetValue(p_Object, null);
                if (_EventList != null && _EventList is EventHandlerList)
                {
                    EventHandlerList _List = (EventHandlerList)_EventList;
                    FieldInfo _FieldInfo = p_EventType.GetField(p_EventName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
                    if (_FieldInfo == null) return null;
                    Delegate _ObjectDelegate = _List[_FieldInfo.GetValue(p_Object)];
                    if (_ObjectDelegate == null) return null;
                    return _ObjectDelegate.GetInvocationList();
                }
            }
            return null;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Delegate[] _List = GetObjectEventList(myButton1, "EventClick", typeof(Control));
            foreach (var item in _List)
            {
                item.DynamicInvoke(sender, e);
            }
        }
        private void Form1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("aaaaaaa");
        }
        private void Form1_DoubleClick(object sender, EventArgs e)
        {
            MessageBox.Show("aaaaa123123aa");
        }
        

        private void richTextBox1_DoubleClick(object sender, EventArgs e)
        {
            MessageBox.Show("aaaaa123123aa1231");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.Show();
        }
    }
}
